import React from 'react';
import { Router, Route, Switch, Redirect } from 'dva/router';
import dynamic from 'dva/dynamic';
import { LocaleProvider } from 'antd';
import zhCn from 'antd/lib/locale-provider/zh_CN';
import App from './pages/Layout';

const RouterConfig = ({ history, app }) => {
  const routes = [
    {
      path: '/login',
      component: () => import('./pages/Login')
    },
    {
      path: '/user/userManage',
      models: () => [import('./models/auth/user/')],
      component: () => import('./components/Auth/User/UserManage')
    },
    {
      path: '/personal/personalManage',
      models: () => [import('./models/auth/personal/')],
      component: () => import('./components/Auth/Personal/PersonalManage')
    },
    {
      path: '/role/roleManage',
      models: () => [import('./models/auth/role/')],
      component: () => import('./components/Auth/Role/RoleManage')
    },
    {
      path: '/company/companyManage',
      models: () => [import('./models/auth/company')],
      component: () => import('./components/Auth/Company/CompanyManage')
    },
    {
      path: '/chart/equipData',
      models: () => [import('./models/chart/index')],
      component: () => import('./components/Chart/List')
    },
    {
      path: '/chart/lineData',
      models: () => [import('./models/chart/lineData')],
      component: () => import('./components/Chart/LineData')
    },
    {
      path: '/chart/dataTemplate',
      models: () => [import('./models/chart/template')],
      component: () => import('./components/Chart/Template')
    },
    {
      path: '/chart/monitorManage',
      models: () => [import('./models/chart/monitorManage')],
      component: () => import('./components/Chart/Monitor')
    },
    // {
    //   path: '/chart/monitorData/:equipmentNo?',
    //   models: () => [import('./models/chart/monitorData')],
    //   component: () => import('./components/Chart/MonitorData')
    // },
    {
      path: '/menu/list',
      models: () => [import('./models/auth/menu')],
      component: () => import('./components/Auth/Menu/List')
    },
    {
      path: '/equipment/list',
      models: () => [import('./models/equipment/list')],
      component: () => import('./components/Equipment/List')
    },
    {
      path: '/log/list',
      models: () => [import('./models/system/log/list')],
      component: () => import('./components/System/Log/List')
    },
    {
      path: '/warn/list',
      models: () => [import('./models/system/warn/list')],
      component: () => import('./components/System/Warn/List')
    },
    {
      path: '/message/list',
      models: () => [import('./models/system/messageList')],
      component: () => import('./components/System/Message/MessageManage')
    },
    {
      path: '/message/sendList',
      models: () => [import('./models/system/messageSendList')],
      component: () => import('./components/System/Message/SendMessageManage')
    },
    {
      path: '/dashboard/monitor',
      models: () => [import('./models/dashboard/monitor')],
      component: () => import('./components/Dashboard/Monitor')
    },
    {
      path: '/chart/monitorManage',
      models: () => [import('./models/chart/monitorManage')],
      component: () => import('./components/Chart/Monitor')
    }
    // 触发器管理
  ];
  return (
    <Router history={history}>
      <LocaleProvider locale={zhCn}>
        <Switch>
          <App>
            <Switch>
              {
                routes.map(({ path, breadcrumbName, exact = true, ...dynamics }, key) => (
                  <Route
                    key={key}
                    exact={exact}
                    path={path}
                    breadcrumbName={breadcrumbName}
                    component={dynamic({
                      app,
                      ...dynamics
                    })}
                  />
                ))
              }
              <Redirect to='/login' />
            </Switch>
          </App>
        </Switch>
      </LocaleProvider>
    </Router>
  );
};

export default RouterConfig;
